<?php

	//set le titre drupal
	$url = $config->getVar('url');
	drupal_set_title('');
	
	drupal_add_js('misc/collapse.js');
	drupal_add_js('bdbdec/view/scripts/jQueryModal.js');
	drupal_add_js('bdbdec/view/scripts/jQuerySelectBox.js');
	drupal_add_js('bdbdec/view/scripts/jQueryAutocomplete.js');
	drupal_add_js('bdbdec/view/scripts/jQueryValidate.js');
	drupal_add_js('bdbdec/view/scripts/ajaxAddObject.js');
	drupal_add_js('bdbdec/view/scripts/jQueryDatePicker.js');
	drupal_add_js('bdbdec/view/scripts/addBook.js');
	
	//ajoute le CSS pour la vue
	drupal_add_css('bdbdec/view/css/autocomplete.css');    
	drupal_add_css('bdbdec/view/css/modal.css');    
	drupal_add_css('bdbdec/view/css/datePicker.css');
	
	
	echo '
	<div id="tabs-wrapper" class="clear-block">
		<h2 class="with-tabs">Ajouter un album</h2>
		<ul class="tabs primary">
			<li class="active">
				<a class="active" href="'.$url.'/bdbdec.php?action=addBook">Ajouter un album</a>
			</li>
			<li>
				<a href="'.$url.'/bdbdec.php?action=changeBook">Modifier un album</a>
			</li>
			<li>
				<a href="'.$url.'/bdbdec.php?action=manageAuthorsSeries">G&eacute;rer la collection</a>
			</li>
		</ul>
	</div>
	<br />
	<strong style="color:red;">Dans le cas d\'un NOUVEL ALBUM</strong>
	
	<form action="'.$url.'/bdbdec.php?action=addBookStep2" method="post" class="formNewAlbum">
		<fieldset class="collapsible '.$collapseNew.'">
			<legend><a href="#">Champs &agrave; remplir en premier lieu</a></legend>
			<p class="field half">
				<label for="publisherList">
					Choisissez l\'editeur :<br />
					<small>
						<a href="./ajax.php?action=ajaxAddElement&amp;typeElement=publisher" class="openModal">
							Ajouter un editeur
						</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					</small>
				</label>
				<select class="publisherList" name="publisherId">';
				foreach($publishersList as $publisher)
					echo '<option value="'.$publisher['id'].'">'.$publisher['name'].'</option>';
				echo '    
				</select>
			</p>
			<p class="field half">
				<label for="serieList">
					Choisissez la s&eacute;rie :<br />
					<small>
						<a href="./ajax.php?action=ajaxAddElement&amp;typeElement=serie" class="openModal">
							Ajouter une s&eacute;rie
						</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					</small>
				</label>
				<select class="serieList" name="serie">';
				foreach($seriesList as $serie)
					echo '<option value="'.$serie['id'].'">'.$serie['name'].'</option>';
				echo '    
				</select>
			</p>
			<p class="field half" id="drawerP">
				<label for="drawerList">
					Choisissez le dessinateur :<br />
					<small>
						<a href="./ajax.php?action=ajaxAddElement&amp;typeElement=drawer" class="openModal">
							Ajouter un dessinateur
						</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					</small>
				</label>
				<select class="drawerList scriptWritterList" name="drawerList[]">';
				foreach($authorsList as $author)
					echo '<option value="'.$author['id'].'">'.$author['name'].'</option>';
				echo '    
				</select>
			</p>
			<p class="field half" id="scriptWritterP">
				<label for="scriptWritterList">
					Choisissez le sc&eacute;nariste :<br />
					<small>
						<a href="./ajax.php?action=ajaxAddElement&amp;typeElement=scriptWritter" class="openModal">
							Ajouter un sc&eacute;nariste
						</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					</small>
				</label>
				<select class="scriptWritterList drawerList" name="scriptWritterList[]">';
				foreach($authorsList as $author)
					echo '<option value="'.$author['id'].'">'.$author['name'].'</option>';
				echo '    
				</select>
			</p>
			<center>
				<small class="tightned">
					<a href="#" id="addScriptWritter" >Ajouter un champ sc&eacute;nariste</a>&nbsp; | &nbsp;
					<a href="#" id="addDrawer" >Ajouter un champ dessinateur</a>&nbsp; | &nbsp;
					<a href="#" id="removeAllFields" >Supprimer tous les champs ajout&eacute;s</a><br />
				</small>
			</center>
		</fieldset>
		
		
		<fieldset class="collapsible collapsed">
			<legend><a href="#">Informations g&eacute;n&eacute;rales sur l\'album</a></legend>
			<p class="field half">
				<label for="bookName">Titre de l\'album : </label>
				<input type="text" name="bookName" class="required"/> 
			</p>
			<p class="field half">
				<label for="bookTome">Tome : </label>
				<input type="text" name="bookTome" class="required"/> 
			</p>
			<p class="field half">
				<label for="bookParutionDate">Date de parution : </label>
				<input type="text" name="bookParutionDate" id="bookParutionDate" class="required"/> 
			</p>
			<p class="field half">
				<label for="bookCotation">Cote : </label>
				<input type="text" name="bookCotation" id="bookCotation" class="required"/> 
			</p>
			<p class="field half">
				<label for="bookEmplacement">Emplacement : </label>
				<select name="bookEmplacement">
					<option value="butc">&Agrave; la BUTC</option>
					<option value="cave">&Agrave; la cave</option>
					<option value="sortie">Sortie</option>
					<option value="reparation">En remplacement</option>
					<option value="remplacement">En r&eacute;paration</option>
					<option value="couvrage">En couvrage</option>
				</select>
			</p>
			<p class="field half">
				<label for="bookCondition">Etat BD : </label>
				<select name="bookCondition">
					<option value="neuf">&Eacute;tat neuf</option>
					<option value="bon">Bon &eacute;tat</option>
					<option value="reparer">&Agrave; r&eacute;parer</option>
					<option value="remplacer">A remplacer</option>
				</select>
			</p>
			<p class="field half">
				<label for="bookEan13">EAN13/ISBN : </label>
				<input type="text" name="bookEan13" id="bookEan13" /> 
			</p>
			<p class="field half">
				<label for="bookYear">Ann&eacute;e d\'edition : </label>
				<select name="bookYear">'.$years.'</select>
			</p>
			<p class="field half">
				<label for="bookPrice">Prix : </label>
				<input type="text" name="bookPrice" id="bookPrice" /> 
			</p>
			<p class="field half" id="textarea">
				<label for="bookDescription">Description : </label>
				<textarea name="bookDescription" id="bookDescription"></textarea>
			</p>
			<p class="field half">
				<br><input type="submit" value="Enregistrer l\'album">
			</p>
		</fieldset>
	</form>
	
	
	<strong style="color:red;">Dans le cas d\'un ALBUM EXISTANT</strong> 
	<small>(nouvel exemplaire d\'un album que BDBDEC poss&egrave;de d&eacute;j&agrave;)</small>
	<div id="bookAlreadyHere">
	<form action="'.$url.'/bdbdec.php?action=addBook&amp;collapseNew=true" method="post" id="formAlbumAlreadyHere">
		<fieldset class="collapsible">
			<legend><a href="#">Choix de l\'album </a></legend>';
		if (isset($albumId) && $albumId)
		{
			echo '
			<input type="hidden" value="'.$albumId.'" name="albumId">
			<p class="field">
				<label for="">Veuillez choisir l\'edition</label>
				<select name="editionSelect" id="editionSelect">
					<option value="0" selected="selected"> - Aucune - </option>';
					foreach ($editionsList as $edition)
						echo '<option value="'.$edition['id'].'">Editeur :'.$edition['publisher'].', annee : '.$edition['year'].', EAN13 : '.$edition['EAN13'].', prix : '.$edition['price'].'</option>';
					echo '
				</select>
			</p>
			<center><strong style="color:red;">ET / OU, remplir ce formulaire</strong></center><br />
			<p class="field">
				<label for="publisherList">
					Choisissez l\'editeur :<br />
					<small>
						<a href="./ajax.php?action=ajaxAddElement&amp;typeElement=publisher" class="openModal">
							Ajouter un editeur
						</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					</small>
				</label>
				<select class="publisherList" id="publisherListSnd" name="publisherId">';
				foreach($publishersList as $publisher)
					echo '<option value="'.$publisher['id'].'">'.$publisher['name'].'</option>';
				echo '    
				</select>
			</p>
			<p class="field">
				<label for="bookEan13">EAN13/ISBN : </label>
				<input type="text" name="bookEan13" id="bookEan13Snd" /> 
			</p>
			<p class="field ">
				<label for="bookYear">Ann&eacute;e d\'edition : </label>
				<input type="text" name="bookYear" id="bookYearSnd" /> 
			</p>
			<p class="field ">
				<label for="bookPrice">Prix : </label>
				<input type="text" name="bookPrice" id="bookPriceSnd" /> 
			</p>
			<p class="field">
				<label for="bookCotation">Cote : </label>
				<input type="text" name="bookCotation" id="bookCotationSnd" /> 
			</p>
			<p class="field">
				<label for="bookEmplacement">Emplacement : </label>
				<select name="bookEmplacement">
					<option value="butc">&Agrave; la BUTC</option>
					<option value="cave">&Agrave; la cave</option>
					<option value="sortie">Sortie</option>
					<option value="reparation">En remplacement</option>
					<option value="remplacement">En r&eacute;paration</option>
					<option value="couvrage">En couvrage</option>
				</select>
			</p>
			<p class="field">
				<label for="bookCondition">Etat BD : </label>
				<select name="bookCondition">
					<option value="neuf">&Eacute;tat neuf</option>
					<option value="bon">Bon &eacute;tat</option>
					<option value="reparer">&Agrave; r&eacute;parer</option>
					<option value="remplacer">A remplacer</option>
				</select>
			</p>
			<p class="field " id="textarea">
				<label for="bookDescription">Description : </label>
				<textarea name="bookDescription" id="bookDescriptionSnd"></textarea>
			</p>';
			foreach($authorsBook as $_author)
			{
				if ($_author['typeAuthor']=='drawer')
					echo '<input type="hidden" name="drawerList[]" value="'.$_author['idAuthor'].'" />';
				else if ($_author['typeAuthor']=='scriptWritter')
					echo '<input type="hidden" name="scriptWritterList[]" value="'.$_author['idAuthor'].'" />';
			}
		}
		else
		{
			echo '
			<p class="field">
				<label for="">Veuillez choisir l\'album</label>
				<select name="aid">';
					foreach ($albumsList as $album)
						echo '<option value="'.$album['id'].'">'.$album['name'].'</option>';
					echo '
				</select>
			</p>';
		}
				
			echo '	
			<p class="full">
				<input type="hidden" value="true" name="edSubmitted">
				<input type="submit" value="Valider">
			</p>    
		</fieldset>
	</form>
	
	
	</div>
	
	<script type="text/javascript">
		$().ready(function() {
			$(".formNewAlbum").validate({
				rules: {
					bookName: {
						required: true
					},
					bookTome: {
						required: true,
						number: true
					},
					bookParutionDate: {
						required: true,
						date: true
					},
					bookCotation: {
						required: true
					},
					bookPrice: {
						number: true
					},
					bookYear: {
						number: true,
						max:2050,
						min:1900
					}
				},
				messages: {
					bookName: {
						required : "Requis"
					},
					bookTome: {
						required: "Requis",
						number: "Numerique"
					},
					bookParutionDate: {
						required: "Requis",
						date: "Date"
					},
					bookCotation: {
						required: "Requis"
					},
					bookPrice: {
						number: "Numerique"
					},
					bookYear: {
						number: "Numerique",
						max : "Date",
						min : "Date"
					}
				}
			});
			$("#formAlbumAlreadyHere").validate({
				rules: {
					bookCotation: {
						required: true
					},
					bookPrice : {
						number: true
					},
					bookYear : {
						number: true,
						max:2050,
						min:1900
					}
				},
				messages: {
					bookCotation: {
						required: "Requis"
					},
					bookPrice : {
						number: "Numerique"
					},
					bookYear : {
						number: "Numerique",
						max : "Date",
						min : "Date"
					}
				}
			});
		});
		
		jQuery(function($){
			$("#bookParutionDate").datepicker();
		});    
	</script>';
	
?>
